﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyHocPhi.GUI.HeThong;
using QuanLyHocPhi.Model;
using QuanLyHocPhi.BLL;
using QuanLyHocPhi.GUI.DuLieu;

namespace QuanLyHocPhi.GUI
{
    using Model;
    using QuanLyHocPhi.GUI.TacNghiep;
    public partial class FormMain : FormBase
    {


        public FormMain()
        {
            InitializeComponent();
        }

        #region Đăng nhập
        private void OnDangNhapClick(object sender, EventArgs e)
        {
            DangNhap();
        }

        public void DangNhap()
        {
            FormDangNhap frm = new FormDangNhap();
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Program.NguoiSuDung = frm.NguoiSuDung;
                if (frm.NguoiSuDung.VaiTro == 2)
                {
                    //backUpToolStripMenuItem.Enabled = true;
                    //backUpToolStripMenuItem.Visible = true;
                }
            }
        }
        #endregion

        #region Đăng xuất
        private void OnDangXuatClick(object sender, EventArgs e)
        {
            DangXuat();
        }

        public void DangXuat()
        {
            Program.NguoiSuDung = null;
        }
        #endregion

        #region Thoát chương trình
        private void OnMenuHeThong_ThoatClick(object sender, EventArgs e)
        {
            ThoatChuongTrinh();
        }

        public void ThoatChuongTrinh()
        {
            this.Close();
        }
        #endregion

        private void OnLoad(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            Program.NguoiSuDung = null;
            //Program.HocKy = null;
            this.DangNhap();
        }

        private void OnMenuHeThong_DoiMatKhauClick(object sender, EventArgs e)
        {
            FormDoiMatKhau frm = new FormDoiMatKhau(Program.NguoiSuDung);
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                DialogUtils.ShowMessage("Đổi mật khẩu thành công!");
            frm = null;
        }

        private void OnMenuDuLieu_NamHocHocKyClick(object sender, EventArgs e)
        {
            FormHocKy frm = new FormHocKy();
            frm.ShowDialog();
            frm = null;
        }

        /// <summary>
        /// Cập nhật hiển thị người sử dụng đang làm việc
        /// </summary>
        internal void UpdateNguoiSuDung()
        {
            if (Program.NguoiSuDung == null)
            {
                #region Huỷ đăng nhập
                menuHeThong_DangNhap.Visible =
                    btnDangNhap.Visible = true;
                menuHeThong_DangXuat.Visible =
                    btnDangXuat.Visible =
                    menuDuLieu.Visible =
                    menuTacNghiep.Visible =
                    menuHeThong_QuanLyNguoiSuDung.Visible =
                    menuHeThong_DoiMatKhau.Visible = false;

                lblStatus.Text = "Chưa đăng nhập";
                #endregion
            }
            else
            {
                #region Thiết lập thông tin người sử dụng
                menuHeThong_DangNhap.Visible =
                    btnDangNhap.Visible = false;
                menuHeThong_DangXuat.Visible =
                    btnDangXuat.Visible =
                    menuDuLieu.Visible =
                    menuTacNghiep.Visible =
                    menuHeThong_QuanLyNguoiSuDung.Visible =
                    menuHeThong_DoiMatKhau.Visible = true;

                lblStatus.Text = string.Format("Đã đăng nhập vai trò {1} - Tên đăng nhập: {0}",
                    Program.NguoiSuDung.TenDangNhap,
                    Program.NguoiSuDung.VaiTroDescription);
                menuHeThong_QuanLyNguoiSuDung.Visible = Program.NguoiSuDung.VaiTro == NguoiSuDung.VaiTro_Admin;
                #endregion
            }
        }

        private void OnMenuTacNghiep_ThuHocPhiSinhVienClick(object sender, EventArgs e)
        {
            FormThuLeHocPhiLop frm = new FormThuLeHocPhiLop();
            frm.ShowDialog();
        }

        private void OnMenuthongKe_Click(object sender, EventArgs e)
        {
            FormThongKeTheoCaNhan frm = new FormThongKeTheoCaNhan();
            frm.ShowDialog();
        }

        private void quanLyPhieuThuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormQuanLyPhieuThu qlpt = new FormQuanLyPhieuThu();
            qlpt.ShowDialog();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormThongTinChuongTrinh frm = new FormThongTinChuongTrinh();
            frm.ShowDialog();
        }

        private void thongKeTheoNgay_Click(object sender, EventArgs e)
        {
            FormThongKeTheoThoiGian frm = new FormThongKeTheoThoiGian();
            frm.ShowDialog();
        }

        private void menuHeThong_QuanLyNguoiSuDung_Click(object sender, EventArgs e)
        {
            FormQuanLyNguoiSuDung frm = new FormQuanLyNguoiSuDung();
            frm.ShowDialog();
        }

        private void menuDuLieu_SinhVien_Click(object sender, EventArgs e)
        {
            FormDanhSachSinhVien frm = new FormDanhSachSinhVien();
            frm.ShowDialog();
            frm = null;
        }

        private void inBanSaoPhieuThuMenuTooltip_Click(object sender, EventArgs e)
        {
            FormInPhieuThu frm = new FormInPhieuThu();
            frm.ShowDialog();
        }

        private void dangKyThongTinMenuTooltip_Click(object sender, EventArgs e)
        {
            FormDangKyThongTin frm = new FormDangKyThongTin();
            frm.ShowDialog();
        }

        private void cauHinhPhieuThuMenuTooltip_Click(object sender, EventArgs e)
        {
            FormCauHinhPhieuThu frm = new FormCauHinhPhieuThu();
            frm.ShowDialog();
        }

        private void thuHocPhiLopMenuTooltip_Click(object sender, EventArgs e)
        {
            FormThuLeHocPhiLop frm = new FormThuLeHocPhiLop();
            frm.ShowDialog();
        }

        private void nopHocPhiCaNhanMenuTooltip_Click(object sender, EventArgs e)
        {
            FormThuLeHocPhiCaNhan frm = new FormThuLeHocPhiCaNhan();
            frm.ShowDialog();
        }

        private void thuLePhiLopMenuTooltip_Click(object sender, EventArgs e)
        {
            FormThuLeHocPhiLop frm = new FormThuLeHocPhiLop(false);
            frm.ShowDialog();
        }

        private void thuLePhiCaNhanMenuTooltip_Click(object sender, EventArgs e)
        {
            FormThuLeHocPhiCaNhan frm = new FormThuLeHocPhiCaNhan(false);
            frm.ShowDialog();
        }

        private void thongKeTheoLopMenutooltip_Click(object sender, EventArgs e)
        {
            FormThongKeTheoLop frm = new FormThongKeTheoLop();
            frm.ShowDialog();
        }
    }
}
